/*
 * 作者：姚俊
 * 功能:发送邮件的action
 * 日期；2015-05-26
 */
package admin.action.mail;

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import admin.email.SendEmail;

public class SendMailsAction {
	
	private String[] emailName;
	private String subject;
	private String content;
	private String toName;

	public String[] getEmailName() {
		return emailName;
	}

	public void setEmailName(String[] emailName) {
		this.emailName = emailName;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getToName() {
		return toName;
	}

	public void setToName(String toName) {
		this.toName = toName;
	}

	public String execute()
	{
		if(this.getToName().equals("")||this.getToName()==null)
		{
			
			for(int i=0;i<this.emailName.length;i++)
			{
				System.out.println("姓名为:"+this.getEmailName()[i]);
				try {
					SendEmail.send_email(this.getEmailName()[i].toString(), this.getSubject(), this.getContent());
				} catch (AddressException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (MessagingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
						
		}
		else if(this.getEmailName().length!=0&&this.getEmailName()!=null)
		{
			try {
				SendEmail.send_email(this.getToName(), this.getSubject(), this.getContent());
			} catch (AddressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MessagingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		
		return "succ";
	}

}
